<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item>
        <i class="el-icon-s-home"></i>
        首页
      </el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 头部导航 -->
    <div class="tab">
      <router-link to="/home">
        <i class="el-icon-arrow-left" style="font-size: 20px; font-weight: bold; color: #000;"></i>
      </router-link>
      <p style="font-size: 14px; font-weight: bold;margin-left: 20px;">导航图标</p>
    </div>
    <!-- 主体 -->
    <div class="content">
      <table>
        <th>图标</th>
        <th>标题</th>
        <th>位置</th>
        <th>操作</th>
        <tr v-for="item in data" :key="item.id">
          <td>
            <img class="icon" :src="item.img" alt="">
          </td>
          <td>{{ item.name }}</td>
          <td>{{ item.address }}</td>
          <td>
            <button @click="setIcon(item)" class="tabbtn">更换图标</button>
          </td>
        </tr>
      </table>
      <!-- 更换 -->
      <div class="zz" v-show="flag">
        <div class="set">
          <div class="setTop">
            <p style="color: #fff;">导航图标管理</p>
            <i class="el-icon-close" style="font-size: 20px;font-weight: bold;color: #fff;" @click="setclose"></i>
          </div>
          <div class="nr">
            <div style="padding: 40px 80px;">
              <div class="lin1">
                <p>原图标:</p>
                <img class="icon1" :src="img" alt="">
              </div>
              <div class="lin1">
                <p>标题:</p>
                <input type="text" v-model="name" class="nameipt">
              </div>
              <div class="lin1">
                <p>点击上传新图标:</p>
                <el-upload class="upload-demo" action="http://127.0.0.1:7001/upload" :on-success="ok"
                      :before-remove="beforeRemove" multiple :limit="1" :on-exceed="handleExceed"
                      :file-list="fileList">
                      <el-button size="small" type="primary">点击上传</el-button>
                      <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
                    </el-upload>
              </div>
              <div class="lin2">
                <button @click="setOk">确定</button>
                <button @click="setclose">取消</button>

              </div>
            </div>
          </div>
          


        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {getIconBx,setIconBx} from '../../utils/api'
export default {
  data() {
    return {
      flag: false,
      name:'秒杀',
      fileList: [],
      data:[],
      setId:0,
      img:'',
      imghttp:''
    }
  },
  created(){
    this.render()
  },
  mounted(){
    this.render()
  },
  methods: {
    setOk(){
      setIconBx({
        id:this.setId,
        name:this.name,
        img:this.imghttp
      }).then(res=>{
        console.log(res);
        if(res.status == 200){
          this.flag = false
          this.render()
        }
      })
    },
    render(){
      getIconBx().then(res=>{
        // console.log(res.data);
        this.data = res.data.data
      })
    },
    setIcon(item) {
      this.img = item.img
      this.flag = true
      this.name = item.name
      this.setId = item.id
    },
    setclose() {
      this.flag = false
    },
    ok(file, fileList) {
      const obj = file.data.replaceAll('\\\\', '\\/')
      const http = "http://127.0.0.1:7001" + obj
       this.imghttp = http.replaceAll("\\", "\/")

    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    }
  }
}
</script>
<style scoped>
.lin2 button {
   border: 1px solid rgba(187, 187, 187, 1);
   color: rgba(16, 16, 16, 1);
   font-size: 14px;
   background-color: #fff;
   border-radius: 5px;
   width: 50px;
   height: 30px;
 }
 .el-upload__tip {
   color: red;
 }
.lin2{
  display: flex;
  width: 40%;
  margin: 0 auto;
  justify-content: space-around;
}
.upload-demo{
  margin-left: 20px;
  margin-top: -6px;
}
.nameipt{
  width: 100px;
  border: none;
  padding:10px;
  margin-left: 60px;
  margin-top: -10px;
}
.icon1{
  width: 25px;
  margin-left: 40px;
  margin-top: -5px;
}
.lin1{
  display: flex;
  margin-bottom: 30px;
}
.nr {
  width: 100%;
  height: 100%;
  font-size: 14px;
}

.setTop {
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  background-color: #0790F5;
}

.set {
  font-size: 14px;
  width: 50%;
  height: 400px;
  position: absolute;
  top: 50%;
  left: 60%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  background: #ffffff;
  border-radius: 5px;

}

.zz {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
}

.icon {
  width: 30px;
}

.tab {
  padding: 20px 40px;
  display: flex;
}

.content {
  width: 85%;
  margin: 40px auto;
  height: 100%;
}

.tabbtn {
  margin-left: 10px;
  margin-right: 10px;
  border: none;
  color: #0790F5;
  font-weight: bold;
  background-color: #fff;
}

table {
  margin-top: 30px;
  border: 1px solid #777777;
  border-collapse: collapse;
  text-align: center;
  width: 100%;
  font-size: 14px;
}

tr {
  height: 50px;
}

td {
  width: 150px;
  border: 1px solid #777777;
}

th {
  height: 50px;
  line-height: 50px;
  font-weight: normal;
  background-color: #F6F6F6;
  border: 1px solid #777777;
}</style>